package com.emmmya.ocs.modules.system.file.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.emmmya.harinCheck.annotation.Check;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.emmmya.ocs.common.base.BaseEntity;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @description:
 * @author: 咕噜肉IT小店-黑医
 * @createDate: 2020-05-14
 * @version: 1.0
 */
@Data
@Table(name="h_file")
@TableName("h_file")
@Entity
public class File extends BaseEntity {


    @Check(name = "原文件名")
    private String fileName;

    @Check(name = "存储文件名")
    @Column(name = "f_key" ,unique = true)
    private String fkey;

    @Check(name = "大小")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long fileSize;

    @Check(name = "文件类型")
    private String fileType;

    @Check(name="文件存储路径")
    private String filePath;

    @Check(name = "路径")
    private String url;

    @Check(name = "文件所在的文件夹ID")
    private Long dirId;

    @Check(name = "存储位置 0本地 1七牛 2阿里 3腾讯 4MinIO")
    private Integer location;

    @Check(name = "返回给前端的class类型")
    @Transient
    @TableField(exist = false)
    private String type;

    public String getType(){
        return this.fileName.substring(this.fileName.lastIndexOf(".")+1,this.fileName.length());
    }

    public void setType(String type){
        this.type = type;
    }
}
